package net.lab1024.sa.admin.module.business.school.dormitory.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.school.dormitory.dao.DormitoryDao;
import net.lab1024.sa.admin.module.business.school.dormitory.domain.entity.DormitoryEntity;
import net.lab1024.sa.admin.module.business.school.dormitory.domain.form.DormitoryAddForm;
import net.lab1024.sa.admin.module.business.school.dormitory.domain.form.DormitoryQueryForm;
import net.lab1024.sa.admin.module.business.school.dormitory.domain.form.DormitoryUpdateForm;
import net.lab1024.sa.admin.module.business.school.dormitory.domain.vo.DormitoryVO;
import net.lab1024.sa.admin.module.business.school.floor.service.FloorService;
import net.lab1024.sa.admin.module.business.school.room.service.RoomService;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 宿舍楼 Service
 *
 * @Author ZouYang
 * @Date 2024-12-28 10:04:28
 * @Copyright ZouYang
 */

@Service
public class DormitoryService {

    @Resource
    private DormitoryDao dormitoryDao;

    @Resource
    private FloorService floorService;

    @Resource
    private RoomService  roomService;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<DormitoryVO> queryPage(DormitoryQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<DormitoryVO> list = dormitoryDao.queryPage(page, queryForm);
        PageResult<DormitoryVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(DormitoryAddForm addForm) {
        DormitoryEntity dormitoryEntity = SmartBeanUtil.copy(addForm, DormitoryEntity.class);
        // 创建楼
        dormitoryDao.insert(dormitoryEntity);
        // 创建层

        // 创建房间

        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(DormitoryUpdateForm updateForm) {
        DormitoryEntity dormitoryEntity = SmartBeanUtil.copy(updateForm, DormitoryEntity.class);
        dormitoryDao.updateById(dormitoryEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)) {
            return ResponseDTO.ok();
        }

        dormitoryDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id) {
            return ResponseDTO.ok();
        }

        dormitoryDao.updateDeleted(id, true);
        return ResponseDTO.ok();
    }
}
